package com.yx.modules.api.controller;

import com.yx.common.annotation.Log;
import com.yx.common.utils.R;
import com.yx.system.entity.TdBook;
import com.yx.system.entity.TdUserProFile;
import com.yx.system.service.TdUserProFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户头像控制器
 */
@RestController
@RequestMapping("/userProFile")
public class TdUserProFileController {

    @Autowired
    private TdUserProFileService tdUserProFileService;

    /**
     * 按ID查询用户头像
     *
     * @return
     */
    @Log
    @PostMapping("findByUid")
    public R findByUId(int id) {
        return R.ok().put("user", tdUserProFileService.selectByPrimaryKey(id));
    }

    /**
     * 新增或修改
     *
     * @return
     */
    @Log
    @PostMapping("saveOrUpdate")
    public R saveOrUpdate(TdUserProFile tdUserProFile) {
        if (tdUserProFile.getId() == 0 || tdUserProFile.getId() == null) {
            tdUserProFileService.insert(tdUserProFile);
        } else {
            tdUserProFileService.updateByPrimaryKey(tdUserProFile);
        }
        return R.ok();
    }

    /**
     * 删除 (软删除)
     *
     * @return
     */
    @Log
    @PostMapping("delete")
    public R delete(int id) {
        tdUserProFileService.deleteByPrimaryKey(id);
        return R.ok();
    }
}
